package com.saodisheng.service.impl;

import com.jfinal.kit.Ret;
import com.jfinal.plugin.activerecord.Db;
import com.saodisheng.model.FriendLink;
import com.saodisheng.service.AdminFriendLinkService;
import org.springframework.stereotype.Service;

import java.util.List;
/**
 * description:
 *
 * @author 扫地生_saodisheng
 * @date 2022/1/29
 */
@Service
public class AdminFriendLinkServiceImpl implements AdminFriendLinkService {
	final FriendLink linkDao = new FriendLink().dao();
	
	@Override
	public List<FriendLink> getFriendLink() {
		List<FriendLink> friendLinks = linkDao.find("select * from friend_link");
		return friendLinks;
	}
	
	@Override
	public Ret delLink(int id) {
		boolean r = Db.deleteById("friend_link", id);
		if (r) {
			return Ret.ok("msg", "删除成功");
		}
		return Ret.fail("msg", "删除失败");
	}
	
	@Override
	public Ret addLink(String siteName, String url, String logo) {
		FriendLink link = new FriendLink();
		
		link.setSiteName(siteName);
		link.setUrl(url);
		link.setLogo("/upload/" + logo);
		if (link.save()) {
			return Ret.ok("msg", "增加成功");
		}
		
		return Ret.fail("msg", "增加失败");
	}
}
